/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

/**
 *
 * @author Cyril
 */
public class TermeOccur {
    private Noeud node;
    private Terme terme;
    private int position;
    

    public TermeOccur(Noeud node, Terme t, int position) {
        this.node = node;
        this.terme = t;
        this.position = position;
    }
    
    public double calculTF() {
        //System.out.println("val nbOcurrTerme => "+this.node.getNbOccursDe(this.terme) +" val terme tot => "+this.node.getNbTermTotal()+" MOT => "+this.terme.getWord());
                
        double tf = (double)this.node.getNbOccursDe(this.terme)/(double)this.node.getNbTermTotal();
        //System.out.println("VAL TF =>"+ tf);
        return tf;
    }
    
    /*********************************************
     **     IDF = Nb section ds Collection      **
     *                  /                       **
     *      Nb de section contenant le terme i  **
     ********************************************/
    public double calculIDF(){
        double idf = Math.log((double)NoeudsCollection.getNbNoeuds()/(double)this.terme.getNbSectionsParentes());
        return idf;
    }
    
    public String getValue() {
        double poids = this.calculIDF()*this.calculTF();
        if (terme.getWord().equals("mont"))
            System.out.println("poids:"+poids+" idDoc : "+this.node.getDocId());
        StringBuilder res = new StringBuilder();
        res.append(this.node.getId()).append(',').append(this.position).append(',').append(poids);
        return res.toString();
    }
}
